package PagePackage;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class addLeaguePage extends internalPageClass {
	@FindBy (name="sport")
	public WebElement sportDropdown;	
	
	@FindBy (name="name")
	public WebElement leagueNameField;
	
	@FindBy (name="gender")
	public WebElement genderDropdown;
	
	@FindBy (xpath="html/body/main/section/main/div/div/form/div[2]/button")
	public WebElement saveLeagueButton;
	
	
	@FindBy (xpath="html/body/main/section/main/div/div/form/div[2]/a")
	public WebElement cancelLeagueButton;
	
	
	public addLeaguePage chooseLeagueSport(String leagueSport) {
		Select select7 = new Select(sportDropdown);
		 select7.selectByVisibleText(leagueSport);
		 return MyPageFactory.getPage(driver, addLeaguePage.class);

		}
	
	
	public addLeaguePage addLeagueName (String leagueName){
		leagueNameField.clear();
		leagueNameField.sendKeys(leagueName);
		 return MyPageFactory.getPage(driver, addLeaguePage.class);
		}
	public addLeaguePage chooseGender(String gender) {
		Select select1 = new Select(genderDropdown);
		 select1.selectByVisibleText(gender);
		 return MyPageFactory.getPage(driver, addLeaguePage.class);

		}
	
	public leaguePage saveLeague (){
		saveLeagueButton.click();
		 return MyPageFactory.getPage(driver, leaguePage.class);
		}
	
	public leaguePage cancelLeague (){
		cancelLeagueButton.click();
		 return MyPageFactory.getPage(driver, leaguePage.class);
		}
	
	
	public addLeaguePage selectedValue (){
		Select select = new Select(sportDropdown);
	    
		WebElement option = select.getFirstSelectedOption();
		option.getText();
	return MyPageFactory.getPage(driver, addLeaguePage.class);
	}
	
	public boolean isOnThisPage(){
		return sportDropdown.isDisplayed();
	}
 @Override
void tryToOpen() {
	MyPageFactory.getPage(driver, loginPageClass.class).loginAs("victoria@krossover.com", "webmaster");
	schooltab.click();
}
}
